SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.[DnnProduct_AutomaticStuckOrderHandling_TodayChecksCount]
	@WhereClause nvarchar(1000)
AS
BEGIN
	DECLARE @SQLString NVARCHAR(1000)

	
	SET @SQLString = N'
		SELECT count(LastOrderStatusesId)
		FROM DnnProduct_AutomaticStuckOrderHandling_LastOrderStatuses
		WHERE DAY([Timestamp]) = DAY(GETDATE()) AND MONTH([Timestamp]) = MONTH(GETDATE()) AND YEAR([Timestamp]) = YEAR(GETDATE())'
	

	IF (LEN(@WhereClause) > 0)
	BEGIN
		SET @SQLString = @SQLString + N' AND ' + @WhereClause
	END
	
	EXECUTE sp_executesql @SQLString
END
GO
